#include "YDXRender/YDXRender.h"

#include <unordered_map>
#include <iostream>

using namespace YXX;
using namespace std;
using namespace DX11;

// void YXX::CommandBuffer::SetPipelineStateObject(ResourceHandle pso)
// {
// 	auto pPSO = ResourcePool::Get().GetPipelineStateObjectByHandle(pso);
// 
// 	pPSO->Apply(mpDeferredContext.Get());
// }												 
// 
// void YXX::CommandBuffer::SetParameterHeap(ResourceHandle paraHeap)
// {
// 	auto pParaHeap = ResourcePool::Get().GetParameterHeapByHandle(paraHeap);
// 
// 	pParaHeap->Apply(mpDeferredContext.Get());
// }
// 
// void CommandBuffer::DrawMesh(ResourceHandle meshHandle)
// {
// 	auto pMesh = ResourcePool::Get().GetMeshDataByHandle(meshHandle);
// 
// 	pMesh->Apply(mpDeferredContext.Get());
// 
// 	FinishRecord();
// }
void YXX::CommandBuffer::SetRenderTargets(std::vector<ID3D11RenderTargetView*> rtvs, ID3D11DepthStencilView* dsv /*= nullptr*/)
{
	
	mpDeferredContext->OMSetRenderTargets(rtvs.size(), rtvs.data(), dsv);
}


void YXX::CommandBuffer::ClearRenderTarget(ID3D11RenderTargetView* rtv)
{

	static float black[4] = { 1,1,0,0 };
	mpDeferredContext->ClearRenderTargetView(rtv, black);
}

void YXX::CommandBuffer::FinishRecord()
{
	ComPtr<ID3D11CommandList> list;
	HR(mpDeferredContext->FinishCommandList(FALSE, list.GetAddressOf()));

	mpd3dCommandLists.emplace_back(move(list));
}

